<?php

class componentComponents extends sfComponents
{
    public function executeCategoriesSideMenu()
    {
        $c = new Criteria();
        $c->add(CmsCategoriesPeer::STATUS_CODE, Globals::STATUS_ACTIVE);
        $c->addAscendingOrderByColumn(CmsCategoriesPeer::CATEGORIES_NAME);
        $this->cmsCategories = CmsCategoriesPeer::doSelect($c);

    }
    public function executeSpecialsSideMenu()
    {
        $query = "SELECT * FROM cms_product T JOIN (
                      SELECT FLOOR(MAX(product_id) * RAND()) AS ID FROM cms_product
                  ) AS x ON T.product_id >= x.ID LIMIT 1";

        $connection = Propel::getConnection();
        $statement = $connection->prepareStatement($query);

        $r2 = $statement->executeQuery();

        if ($r2->next()) {
            $this->specialItem = $r2->getRow();
        }
    }
    public function executeRoundabout()
    {
        $c = new Criteria();
        $c->add(ComponentRoundaboutPeer::STATUS_CODE, Globals::STATUS_ACTIVE);
        $c->add(ComponentRoundaboutPeer::ROUNDABOUT_ID, $this->param);
        $componentRoundabout = ComponentRoundaboutPeer::doSelectOne($c);

        if ($componentRoundabout) {
            $this->componentRoundabout = $componentRoundabout;

            $c = new Criteria();
            $c->add(ComponentRoundaboutPeer::ROUNDABOUT_ID, $componentRoundabout->getRoundaboutId());
            $this->componentRoundaboutDetails = ComponentRoundaboutDetailPeer::doSelect($c);
        }
    }
    public function executeFancybox()
    {
        $c = new Criteria();
        $c->add(CmsProductPeer::PRODUCT_ID, $this->param);
        $product = CmsProductPeer::doSelectOne($c);

        if ($product) {
            $this->product = $product;

            $c = new Criteria();
            $c->add(CmsProductImagePeer::PRODUCT_ID, $product->getProductId());
            $c->add(CmsProductImagePeer::STATUS_CODE, Globals::STATUS_ACTIVE);
            $c->addAscendingOrderByColumn(CmsProductImagePeer::SEQ);
            $this->productImages = CmsProductImagePeer::doSelect($c);
        }
    }
    public function executeCountrySelectOption()
    {
        $this->countrySelected = $this->countrySelected;
        $this->countryName = $this->countryName;
        $this->countryId = $this->countryId;
    }
}